<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
	<script type="text/javascript">
		//递归函数：函数直接或间接调用函数本身，该函数就叫递归函数
		//递归函数必须要有结束条件，防止无限循环
		// function fn(){
		// 	console.log("递归函数")
		// 	fn()
		// }
		// fn()

		//你爱不爱我
		function fn(){
			var end = confirm("请我吃肯德基")
			if (end){
				return false;
			}else{
				fn()
			}
		}
		fn()

		//1--n数字和
		function getSum(n){
			if(n <= 1){
				return 1
			}else{
				return n + getSum(n - 1)
				//10 + f(9)
					  //f(9) = 9 + f(8)
						//f(8) = 8 + f(7)
						 //f(7) = 7 + f(6)
						  //f(6) = 6 + f(5)
							//f(5) = 5 + f(4)
							  //f(4) = 4 + f(3)
								//f(3) = 3 + f(2)
								 //f(2) = 2 + f(1)
			}
		}
		console.log(getSum(10))
	</script>
</body>
</html>